package com.platform.module.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.platform.module.dao.entity.TokenRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author Long
 * @description
 **/
public interface TokenMapper extends BaseMapper<TokenRecord> {

    @Insert("insert into tb_token (user_id,caccesstoken,iexpiresin) values(#{userId},#{caccesstoken},#{iexpiresin})")
    int addToken(TokenRecord record);

    @Select("select * from tb_token where user_id = #{userId} and istate = #{state} and ccreated_time >= date_sub(NOW(), interval 31 DAY)")
    List<TokenRecord> findTokenListByUserIdAndState(@Param("userId") Long userId, @Param("state") int state);

    @Update("update tb_token set istate = 1 where id = #{id}")
    void updateTokenStateById(@Param("id") Long id);

}
